package com.hunliji.monitor.web.strategy.alert.util;

import static com.hunliji.monitor.share.constants.AlertTemplateConstant.*;

import com.hunliji.monitor.share.constants.AlertTemplateConstant;
import com.hunliji.monitor.share.constants.AlertTemplateConstant.*;
import com.hunliji.monitor.web.model.param.AliyunAlertNotifyParam;
import java.util.Objects;
import org.springframework.util.StringUtils;

/**
 * File：TemplateUtil.java<br> Title: <br> Description: <br>
 *
 * @author lejin Date: 2022/10/12
 */
public class TemplateUtil {

    public static String getConstantByTemplate(String template, AliyunAlertNotifyParam param){
        if(StringUtils.isEmpty(template)){
            return template;
        }
        return template.replace(ALERT_ID, param.getAlertId())
            .replace(PROJECT, param.getProject())
            .replace(ALERT_NAME, param.getAlertName())
            .replace(ALERT_TYPE, param.getAlertType())
            .replace(ALERT_URL, param.getAlertUrl())
            .replace(ALERT_TIME, param.getAlertTime())
            .replace(FIRE_TIME, param.getFireTime())
            .replace(SEVERITY, Objects.nonNull(param.getSeverity()) ? param.getSeverity().toString() : null)
            .replace(ALERT_MSG, param.getAlertMsg())
            .replace(ALERT_COUNT, param.getAlertCount());
    }
}
